package com.pokerpro.Scanner;

import java.awt.Color;
import static com.pokerpro.Constant.Colors.*;
import static com.pokerpro.Constant.Positions.*;
import static com.pokerpro.support.Log.*;

import java.awt.Point;
import java.awt.Robot;
import java.util.List;
import com.pokerpro.interfaces.TableEvents;
import com.pokerpro.model.HoleCards;
import com.pokerpro.support.BaseElement;

/**
 * Scans the position of holecards and trigger Event if new cards are dealt or
 * hand is gone
 * 
 * @author Alex
 * 
 */
public class HoleCardsScanner extends BaseElement implements Runnable {

	TableEvents ev;
	private Point CardLeftPosition;
	private Point CardRightPosition;
	private HoleCards holeCards;

	public HoleCardsScanner(Robot robot, List<Point> pPoints, TableEvents ev) {
		super(robot);
		this.ev = ev;
		CardLeftPosition = pPoints.get(0);
		CardRightPosition = pPoints.get(1);
		holeCards = new HoleCards();
	}

	public void run() {
		log("HoleCardsScanner runs!");
		boolean b = false;
		while (true) {
			Color acutalColor = getPixelCol(TABLE1_CARD_STANDARD_COLOR_POSITION);
			if (acutalColor.equals(COLOR_CARD_STANDARD) && b==false) {
				log("Karten Wechsel erkannt");
				scanHand();
				ev.newHoleCards(holeCards);
				b=true;
			}
			else if (!acutalColor.equals(COLOR_CARD_STANDARD)){
				b=false;
			}
		}
	}

	public void scanHand() {
		
		log("Scan hand");
		Color colorLeftCard = getPixelCol(CardLeftPosition);
		Color colorRightCard = getPixelCol(CardRightPosition);
		/*
		 * 2er
		 */
		if (colorLeftCard.equals(COLOR_CARD_2_CLUB))
			holeCards.setCardLeft("2:club");
		if (colorRightCard.equals(COLOR_CARD_2_CLUB))
			holeCards.setCardRight("2:club");

		if (colorLeftCard.equals(COLOR_CARD_2_DIAMOND))
			holeCards.setCardLeft("2:diamond");
		if (colorRightCard.equals(COLOR_CARD_2_DIAMOND))
			holeCards.setCardRight("2:diamond");

		if (colorLeftCard.equals(COLOR_CARD_2_HEART))
			holeCards.setCardLeft("2:heart");
		if (colorRightCard.equals(COLOR_CARD_2_HEART))
			holeCards.setCardRight("2:heart");

		if (colorLeftCard.equals(COLOR_CARD_2_SPADE))
			holeCards.setCardLeft("2:spade");
		if (colorRightCard.equals(COLOR_CARD_2_SPADE))
			holeCards.setCardRight("2:spade");

		/*
		 * 3er
		 */
		if (colorLeftCard.equals(COLOR_CARD_3_CLUB))
			holeCards.setCardLeft("3:club");
		if (colorRightCard.equals(COLOR_CARD_3_CLUB))
			holeCards.setCardRight("3:club");

		if (colorLeftCard.equals(COLOR_CARD_3_DIAMOND))
			holeCards.setCardLeft("3:diamond");
		if (colorRightCard.equals(COLOR_CARD_3_DIAMOND))
			holeCards.setCardRight("3:diamond");

		if (colorLeftCard.equals(COLOR_CARD_3_HEART))
			holeCards.setCardLeft("3:heart");
		if (colorRightCard.equals(COLOR_CARD_3_HEART))
			holeCards.setCardRight("3:heart");

		if (colorLeftCard.equals(COLOR_CARD_3_SPADE))
			holeCards.setCardLeft("3:spade");
		if (colorRightCard.equals(COLOR_CARD_3_SPADE))
			holeCards.setCardRight("3:spade");

		/*
		 * 4er
		 */

		if (colorLeftCard.equals(COLOR_CARD_4_CLUB))
			holeCards.setCardLeft("4:club");
		if (colorRightCard.equals(COLOR_CARD_4_CLUB))
			holeCards.setCardRight("4:club");

		if (colorLeftCard.equals(COLOR_CARD_4_DIAMOND))
			holeCards.setCardLeft("4:diamond");
		if (colorRightCard.equals(COLOR_CARD_4_DIAMOND))
			holeCards.setCardRight("4:diamond");

		if (colorLeftCard.equals(COLOR_CARD_4_HEART))
			holeCards.setCardLeft("4:heart");
		if (colorRightCard.equals(COLOR_CARD_4_HEART))
			holeCards.setCardRight("4:heart");

		if (colorLeftCard.equals(COLOR_CARD_4_SPADE))
			holeCards.setCardLeft("4:spade");
		if (colorRightCard.equals(COLOR_CARD_4_SPADE))
			holeCards.setCardRight("4:spade");

		/*
		 * 5er
		 */
		if (colorLeftCard.equals(COLOR_CARD_5_CLUB))
			holeCards.setCardLeft("5:club");
		if (colorRightCard.equals(COLOR_CARD_5_CLUB))
			holeCards.setCardRight("5:club");

		if (colorLeftCard.equals(COLOR_CARD_5_DIAMOND))
			holeCards.setCardLeft("5:diamond");
		if (colorRightCard.equals(COLOR_CARD_5_DIAMOND))
			holeCards.setCardRight("5:diamond");

		if (colorLeftCard.equals(COLOR_CARD_5_HEART))
			holeCards.setCardLeft("5:heart");
		if (colorRightCard.equals(COLOR_CARD_5_HEART))
			holeCards.setCardRight("5:heart");

		if (colorLeftCard.equals(COLOR_CARD_5_SPADE))
			holeCards.setCardLeft("5:spade");
		if (colorRightCard.equals(COLOR_CARD_5_SPADE))
			holeCards.setCardRight("5:spade");

		/*
		 * 6er
		 */
		if (colorLeftCard.equals(COLOR_CARD_6_CLUB))
			holeCards.setCardLeft("6:club");
		if (colorRightCard.equals(COLOR_CARD_6_CLUB))
			holeCards.setCardRight("6:club");

		if (colorLeftCard.equals(COLOR_CARD_6_DIAMOND))
			holeCards.setCardLeft("6:diamond");
		if (colorRightCard.equals(COLOR_CARD_6_DIAMOND))
			holeCards.setCardRight("6:diamond");

		if (colorLeftCard.equals(COLOR_CARD_6_HEART))
			holeCards.setCardLeft("6:heart");
		if (colorRightCard.equals(COLOR_CARD_6_HEART))
			holeCards.setCardRight("6:heart");

		if (colorLeftCard.equals(COLOR_CARD_6_SPADE))
			holeCards.setCardLeft("6:spade");
		if (colorRightCard.equals(COLOR_CARD_6_SPADE))
			holeCards.setCardRight("6:spade");

		/*
		 * 7er
		 */
		if (colorLeftCard.equals(COLOR_CARD_7_CLUB))
			holeCards.setCardLeft("7:club");
		if (colorRightCard.equals(COLOR_CARD_7_CLUB))
			holeCards.setCardRight("7:club");

		if (colorLeftCard.equals(COLOR_CARD_7_DIAMOND))
			holeCards.setCardLeft("7:diamond");
		if (colorRightCard.equals(COLOR_CARD_7_DIAMOND))
			holeCards.setCardRight("7:diamond");

		if (colorLeftCard.equals(COLOR_CARD_7_HEART))
			holeCards.setCardLeft("7:heart");
		if (colorRightCard.equals(COLOR_CARD_7_HEART))
			holeCards.setCardRight("7:heart");

		if (colorLeftCard.equals(COLOR_CARD_7_SPADE))
			holeCards.setCardLeft("7:spade");
		if (colorRightCard.equals(COLOR_CARD_7_SPADE))
			holeCards.setCardRight("7:spade");

		/*
		 * 8er
		 */
		if (colorLeftCard.equals(COLOR_CARD_8_CLUB))
			holeCards.setCardLeft("8:club");
		if (colorRightCard.equals(COLOR_CARD_8_CLUB))
			holeCards.setCardRight("8:club");

		if (colorLeftCard.equals(COLOR_CARD_8_DIAMOND))
			holeCards.setCardLeft("8:diamond");
		if (colorRightCard.equals(COLOR_CARD_8_DIAMOND))
			holeCards.setCardRight("8:diamond");

		if (colorLeftCard.equals(COLOR_CARD_2_HEART))
			holeCards.setCardLeft("8:heart");
		if (colorRightCard.equals(COLOR_CARD_2_HEART))
			holeCards.setCardRight("8:heart");

		if (colorLeftCard.equals(COLOR_CARD_8_SPADE))
			holeCards.setCardLeft("8:spade");
		if (colorRightCard.equals(COLOR_CARD_8_SPADE))
			holeCards.setCardRight("8:spade");

		/*
		 * 9er
		 */
		if (colorLeftCard.equals(COLOR_CARD_9_CLUB))
			holeCards.setCardLeft("9:club");
		if (colorRightCard.equals(COLOR_CARD_9_CLUB))
			holeCards.setCardRight("9:club");

		if (colorLeftCard.equals(COLOR_CARD_9_DIAMOND))
			holeCards.setCardLeft("9:diamond");
		if (colorRightCard.equals(COLOR_CARD_9_DIAMOND))
			holeCards.setCardRight("9:diamond");

		if (colorLeftCard.equals(COLOR_CARD_9_HEART))
			holeCards.setCardLeft("9:heart");
		if (colorRightCard.equals(COLOR_CARD_9_HEART))
			holeCards.setCardRight("9:heart");

		if (colorLeftCard.equals(COLOR_CARD_9_SPADE))
			holeCards.setCardLeft("9:spade");
		if (colorRightCard.equals(COLOR_CARD_9_SPADE))
			holeCards.setCardRight("9:spade");

		/*
		 * 10er
		 */
		if (colorLeftCard.equals(COLOR_CARD_10_CLUB))
			holeCards.setCardLeft("10:club");
		if (colorRightCard.equals(COLOR_CARD_10_CLUB))
			holeCards.setCardRight("10:club");

		if (colorLeftCard.equals(COLOR_CARD_10_DIAMOND))
			holeCards.setCardLeft("10:diamond");
		if (colorRightCard.equals(COLOR_CARD_10_DIAMOND))
			holeCards.setCardRight("10:diamond");

		if (colorLeftCard.equals(COLOR_CARD_10_HEART))
			holeCards.setCardLeft("10:heart");
		if (colorRightCard.equals(COLOR_CARD_10_HEART))
			holeCards.setCardRight("10:heart");

		if (colorLeftCard.equals(COLOR_CARD_10_SPADE))
			holeCards.setCardLeft("10:spade");
		if (colorRightCard.equals(COLOR_CARD_10_SPADE))
			holeCards.setCardRight("10:spade");

		/*
		 * Jacks
		 */
		if (colorLeftCard.equals(COLOR_CARD_J_CLUB))
			holeCards.setCardLeft("jack:club");
		if (colorRightCard.equals(COLOR_CARD_J_CLUB))
			holeCards.setCardRight("jack:club");

		if (colorLeftCard.equals(COLOR_CARD_J_DIAMOND))
			holeCards.setCardLeft("jack:diamond");
		if (colorRightCard.equals(COLOR_CARD_J_DIAMOND))
			holeCards.setCardRight("jack:diamond");

		if (colorLeftCard.equals(COLOR_CARD_J_HEART))
			holeCards.setCardLeft("jack:heart");
		if (colorRightCard.equals(COLOR_CARD_J_HEART))
			holeCards.setCardRight("jack:heart");

		if (colorLeftCard.equals(COLOR_CARD_J_SPADE))
			holeCards.setCardLeft("jack:spade");
		if (colorRightCard.equals(COLOR_CARD_J_SPADE))
			holeCards.setCardRight("jack:spade");

		/*
		 * Queens
		 */
		if (colorLeftCard.equals(COLOR_CARD_Q_CLUB))
			holeCards.setCardLeft("queen:club");
		if (colorRightCard.equals(COLOR_CARD_Q_CLUB))
			holeCards.setCardRight("queen:club");

		if (colorLeftCard.equals(COLOR_CARD_Q_DIAMOND))
			holeCards.setCardLeft("queen:diamond");
		if (colorRightCard.equals(COLOR_CARD_Q_DIAMOND))
			holeCards.setCardRight("queen:diamond");

		if (colorLeftCard.equals(COLOR_CARD_Q_HEART))
			holeCards.setCardLeft("queen:heart");
		if (colorRightCard.equals(COLOR_CARD_Q_HEART))
			holeCards.setCardRight("queen:heart");

		if (colorLeftCard.equals(COLOR_CARD_Q_SPADE))
			holeCards.setCardLeft("queen:spade");
		if (colorRightCard.equals(COLOR_CARD_Q_SPADE))
			holeCards.setCardRight("queen:spade");

		/*
		 * Kings
		 */
		if (colorLeftCard.equals(COLOR_CARD_K_CLUB))
			holeCards.setCardLeft("king:club");
		if (colorRightCard.equals(COLOR_CARD_K_CLUB))
			holeCards.setCardRight("king:club");

		if (colorLeftCard.equals(COLOR_CARD_K_DIAMOND))
			holeCards.setCardLeft("king:diamond");
		if (colorRightCard.equals(COLOR_CARD_K_DIAMOND))
			holeCards.setCardRight("king:diamond");

		if (colorLeftCard.equals(COLOR_CARD_K_HEART))
			holeCards.setCardLeft("king:heart");
		if (colorRightCard.equals(COLOR_CARD_K_HEART))
			holeCards.setCardRight("king:heart");

		if (colorLeftCard.equals(COLOR_CARD_K_SPADE))
			holeCards.setCardLeft("king:spade");
		if (colorRightCard.equals(COLOR_CARD_K_SPADE))
			holeCards.setCardRight("king:spade");

		/*
		 * Aces
		 */
		if (colorLeftCard.equals(COLOR_CARD_A_CLUB))
			holeCards.setCardLeft("ace:club");
		if (colorRightCard.equals(COLOR_CARD_A_CLUB))
			holeCards.setCardRight("ace:club");

		if (colorLeftCard.equals(COLOR_CARD_A_DIAMOND))
			holeCards.setCardLeft("ace:diamond");
		if (colorRightCard.equals(COLOR_CARD_A_DIAMOND))
			holeCards.setCardRight("ace:diamond");

		if (colorLeftCard.equals(COLOR_CARD_A_HEART))
			holeCards.setCardLeft("ace:heart");
		if (colorRightCard.equals(COLOR_CARD_A_HEART))
			holeCards.setCardRight("ace:heart");

		if (colorLeftCard.equals(COLOR_CARD_A_SPADE))
			holeCards.setCardLeft("ace:spade");
		if (colorRightCard.equals(COLOR_CARD_A_SPADE))
			holeCards.setCardRight("ace:spade");

		// log(holeCards.getCardLeft().getValue() +
		// holeCards.getCardLeft().getSuit() + "      " +
		// holeCards.getCardRight().getValue() +
		// holeCards.getCardRight().getSuit());
	}
}
